package com.bwie.controller;

import com.bwie.domain.TbProd;
import com.bwie.service.TbProdService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2024/10/16 14:28
 */


@RestController
@RequestMapping(value = "/prod/prod")
public class TbProdController {

    @Autowired
    TbProdService tbProdService;

    @PostMapping(value = "/getProdList")
    public R getProdList(@RequestBody PageInfoVo pageInfoVo) {
        return tbProdService.getProdList(pageInfoVo);
    }

    /**
     * 检查商品库存
     * @param prodId
     * @param prodCount
     * @return
     */
    @GetMapping(value = "/checkStock/{prodId}/{prodCount}")
    public R checkStock(@PathVariable("prodId") Integer prodId, @PathVariable("prodCount") Integer prodCount) {
        return tbProdService.checkStock(prodId, prodCount);
    }

    @PostMapping(value = "/addProd")
    public R addProd(@RequestBody TbProd tbProd) {
        return tbProdService.addProd(tbProd);
    }

    @PostMapping(value = "/delProd/{prodId}")
    public R delProd(@PathVariable("prodId") Integer prodId) {
        return tbProdService.delProd(prodId);
    }

    @PostMapping(value = "/updateProd")
    public R updateProd(@RequestBody TbProd tbProd) {
        return tbProdService.updateProd(tbProd);
    }

    @PostMapping(value = "/deleteAllProd")
    public R deleteAllProd(@RequestBody ArrayList<Integer> prodIds) {
        return tbProdService.deleteAllProd(prodIds);
    }

    /**
     * 商品上架或者下架
     * @param prodId
     * @param flag
     * @return
     */
    @PostMapping(value = "/doUpProd/{prodId}/{flag}")
    public R doUpProd(@PathVariable("prodId") Integer prodId, @PathVariable("flag") Integer flag) {
        return tbProdService.doUpProd(prodId, flag);
    }

    /**
     * 上架所有商品
     * @return
     */
    @PostMapping(value = "/doUpAllProd")
    public R doUpAllProd(@RequestBody ArrayList<Integer> prodIds) {
        return tbProdService.doUpAllProd(prodIds);
    }

    @PostMapping(value = "/uploadPro")
    public R uploadProdImg(@RequestPart("file") MultipartFile file) {
        return tbProdService.uploadProdImg(file);
    }

    /**
     * 获取产品库存数据，用来显示echarts图标
     * @return
     */
    @PostMapping(value = "/getProdStock")
    public R getProdStock() {
        return tbProdService.getProdStock();
    }

    /**
     * 获取商品价格数据，用来显示echarts柱状图
     * @return
     */
    @PostMapping(value = "/getProdPrice")
    public R getProdPrice() {
        return tbProdService.getProdPrice();
    }
}
